package exception;

import java.io.FileOutputStream;
import java.io.IOException;

public class FinallyDemo2 {
    public static void main(String[] args) {
        FileOutputStream fos=null;
        try {
            //ctrl+alt+t自动添加try catch
            fos=new FileOutputStream("fos.txt");
            fos.write(1);
        } catch (IOException e) {
            System.out.println("出错了，并解决了");
        } finally {
            try {
                if(fos!=null){fos.close();}//确保fos能够关闭
            } catch (IOException e) {
                System.out.println("出错了");;
            }

        }
    }
}
